package BitManipulation;

public class _762_PrimeNumberofSetBitsinBinaryRepresentation {
    //hint:1 is not prime number,2 is prime number
    public int countPrimeSetBits(int L, int R) {
        int count = 0;
        for (int i = L; i <=R ; i++) {
            int tempCount = 0;
            int number = i;
            while (number != 0) {
                if ((number & 1) == 1) {
                    tempCount++;
                }
                number = number >> 1;
            }
//            System.out.println(tempCount);
            if (isPrimeNumber(tempCount)) {
                count++;
            }
        }
        return count;
    }

    //get prime number method
    public boolean isPrimeNumber(int num) {
        if (num == 1) {
            return false;
        } else if (num == 2) {
            return true;
        } else {
            if (num % 2 == 0) {
                return true;
            } else {
                for (int i = 3; i <= Math.sqrt(num); i += 2) {
                    if (num % i == 0) {
                        return false;
                    }
                }
            }
        }
        return true;
    }
}
